<?php

ini_set('date.timezone','Asia/Shanghai');
/**
 * Created by PhpStorm.
 * User: SnGef
 * Date: 2017/6/28
 * Time: 16:15
 */

class WechatPay
{
    public function __construct()
    {

    }

    public function XdianWechatPay($payParams)
    {
        global $_W, $_GPC;
        $orderSn = $payParams["orderSn"];//充值模块中的订单号，此号码用于业务模块中区分订单，交易的识别码
        $title = $payParams["title"];//收银台中显示的标题
        $amount = $payParams["amount"];//收款金额
        $user = $_W['member']['uid']; //付款用户, 付款的用户名(选填项)


//①、获取用户openid
        $tools = new JsApiPay();
        $openId = $tools->GetOpenid();

//②、统一下单
        $input = new WxPayUnifiedOrder();
        $input->SetBody($payParams["title"]);
        $input->SetAttach($payParams["title"]);
        $input->SetOut_trade_no($payParams["orderSn"]);
        $input->SetTotal_fee($payParams["amount"]);
        $input->SetTime_start(date("YmdHis"));
        $input->SetTime_expire(date("YmdHis", time() + 600));
        $input->SetGoods_tag($payParams["title"]);
        $input->SetNotify_url($_W["siteroot"]."xdian/inc/mobile/wechat_notify.php");
        $input->SetTrade_type("JSAPI");
        $input->SetOpenid($openId);
        $order = WxPayApi::unifiedOrder($input);
        echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
        printf_info($order);
        $jsApiParameters = $tools->GetJsApiParameters($order);






    }
}
